package com.milk.nettylearn.nio.c2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class TestFileChannelTransferTo {
    public static void main(String[] args) {
        try (FileChannel from = new FileInputStream("D:\\win10\\Windows.iso").getChannel();
             FileChannel to = new FileOutputStream("D:\\win10\\Windows_copy.iso").getChannel()
        ) {
            long size = from.size();
            for (long left = size; left > 0; ) {
                System.out.printf("size:%s,left:%s%n", size, left);
                left -= from.transferTo((size - left), left, to);
            }

        } catch (IOException e) {
        }
    }
}
